package com.remote;

import android.os.Bundle;
import android.os.Message;
import android.widget.ToggleButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.view.View.OnClickListener;
import android.view.View;
import android.util.Log;

public class RhythmboxControl extends Remote{
    private ToggleButton mute_toggle;
    
    @Override
    protected void parseMessage(Message msg){
        Log.i(TAG,"Received msg");
        switch(msg.what){
            case Params.MSG_REGISTER_ACTIVITY:
                sendMsg(Params.MSG_SOUND_GET);
                break;
            case Params.MSG_SOUND_SET:
                if(msg.arg1 == 0) mute_toggle.setChecked(true);
                else mute_toggle.setChecked(false);
                break;
            default:
                Log.d(TAG,"Parsing unknown message");
                break;
        }
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rhythmbox_control);
        
        mute_toggle = (ToggleButton)findViewById(R.id.mute_toggle);
        mute_toggle.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.mute_toggle_bg));
        
        mute_toggle.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
                if(mute_toggle.isChecked()){
                    sendMsg(Params.MSG_SOUND_SET,0);
                }else{
                    sendMsg(Params.MSG_SOUND_SET,1);
                }
            }
        });
        
        // HUGE TODO .. make it into single onclicklistener
        ImageView prev = (ImageView)findViewById(R.id.previous);
        prev.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
				sendMsg(Params.SEND_PACKET,Utils.getStringBundle("action|rhythmbox|previous"));
            }
        });
        ImageView next = (ImageView)findViewById(R.id.next);
        next.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
				sendMsg(Params.SEND_PACKET,Utils.getStringBundle("action|rhythmbox|next"));
            }
        });
        ImageView play = (ImageView)findViewById(R.id.play);
        play.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
				sendMsg(Params.SEND_PACKET,Utils.getStringBundle("action|rhythmbox|playpause"));
            }
        });
        ImageView stop = (ImageView)findViewById(R.id.stop);
        stop.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v){
				sendMsg(Params.SEND_PACKET,Utils.getStringBundle("action|rhythmbox|stop"));
            }
        });
        
        SeekBar volControl = (SeekBar)findViewById(R.id.volume);
        volControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
			@Override
			public void onStopTrackingTouch(SeekBar arg0) {

			}

			@Override
			public void onStartTrackingTouch(SeekBar arg0) {

			}
			
			@Override
			public void onProgressChanged(SeekBar arg0,int arg1,boolean arg2){
				Log.d("Progress",String.valueOf(arg1));
				sendMsg(Params.SEND_PACKET,Utils.getStringBundle("action|sound|setvolume|"+String.valueOf(arg1+50)));
			}
		});
        
    }
    
    
    @Override
    public void onStart(){
        super.onStart();
    }
}
